package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.OrderSetting;
import com.itheima.manager.OrderSettingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orderSetting")
public class OmsOrderSettingController {

    @Autowired
    private OrderSettingManager orderSettingManager;

    /**
     * 修改指定订单设置
     *
     * @param id:订单设置表中的主键id(按理说是订单id)
     * @param orderSetting:订单设置数据
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id, @RequestBody OrderSetting orderSetting) {
        Integer count = orderSettingManager.update(id, orderSetting);
        if (count == 0) {
            return R.error("修改失败");
        }
        return R.success("修改成功!");
    }

    /**
     * 获取指定订单设置
     *
     * @param id：订单设置表中的主键id(按理说是订单id)
     * @return
     */
    @GetMapping("/{id}")
    public R findById(@PathVariable Integer id) {
        OrderSetting orderSetting = orderSettingManager.findById(id);
        if (orderSetting == null) {
            return R.error("查询有误");
        }
        return R.success(orderSetting);
    }
}